package com.ie.controller;


import com.ie.common.http.Result;
import com.ie.entity.Messages;
import com.ie.service.MessagesService;
import org.apache.logging.log4j.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * messagesController
 *
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/messages")
public class MessagesController
{
    @Autowired
    private MessagesService messagesService;

    @RequestMapping("/all")
    public Result getAllMessages()
    {
        return Result.build(messagesService.getAllMessages(),1,"查询成功");
    }
    //删除
    @DeleteMapping("/delete")
    public Result deleteMessage(@RequestParam("id") String id) {
        if (messagesService.deleteMessage(id)) {
            return Result.build(null, 1, "删除成功");
        }
        return Result.build(null, 0, "删除失败");
    }
    //添加留言
        @PostMapping("/add")
    public Result addMessage( @RequestBody Messages message) {
        System.err.println(message);
        if (messagesService.addMessage(message.getUsername(),message.getMessage())) {
            return Result.build(null, 1, "添加成功");
        }
        return Result.build(null, 0, "添加失败");
    }
}
